package com.wms.utils;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;

import org.apache.commons.lang.StringUtils;

public class URLUtil {

	public static String sendGet(String strURL, String param) throws Exception {
		
		String result = " ";
		String urlName = " ";
		
		try {
			
			urlName = strURL + StringUtils.defaultString(param);
			URL url = new URL(urlName);
			
			URLConnection connection = url.openConnection();
			connection.connect();
			
			BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "gb2312"));
			
			String line;
			
			while ((line = in.readLine()) != null) {
				result += line;
			}
			
			in.close();
		}
		catch (Exception e) {
			
			System.out.println("与服务器连接发生异常错误     : " + e.toString());
			System.out.println("连接地址是     : " + urlName);
			
			throw e;
		}
		
		return result;
	}
	
	public static void main(String[] args) {
		
		String result;
		try {
			result = URLUtil.sendGet("http://whois.pconline.com.cn/ip.jsp?ip=127.0.0.1", null);

			System.out.println(result);
		} 
		catch (Exception e) {
			
			e.printStackTrace();
		}
	}
}